<?php 
/**
 * 词条操作
 DROP TABLE IF EXISTS `dict_item`;
CREATE TABLE `dict_item` (
  `i_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `d_id` int(10) unsigned NOT NULL,
  `u_id` int(10) unsigned NOT NULL,
  `itemname` varchar(255) NOT NULL,
  `definition` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`i_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 */
Class ItemModel extends RelationModel{
  protected $_link = array(
      'Example' => array(
          'mapping_type'  => HAS_MANY,
          'class_name'    => 'Example',
          'foreign_key'   => 'i_id',
          // 'mapping_name'  => 'examples',
          // 'mapping_order' => ''
        ),
      'Document' => array(
          'mapping_type'  => BELONGS_TO,
          'class_name'    => "Document",
          'foreign_key'   => "d_id",
          "mapping_fields" => "d_id, docname"
        ), 
    );

  public function selectAllItem()
  {
    return $this->select();
  }

  public function selectItemByIid(int $i_id)
  {
    return $this->where('i_id=' . $i_id)->find();
  }

  public function selectItemByDid(int $d_id)
  {
    return $this->where('d_id=' . $d_id)->select();
  }

  public function selectItemByUid(int $u_id)
  {
    return $this->where('u_id=' . $u_id)->select();
  }

  public function selectItemByPage(int $page, int $listRows)
  {
    return $this->page($page, $listRows)->select();
  }

  public function addItem($data)
  {
    return $this->add($data);
  }

  public function updateItem($data)
  {
    return $this->save($data);
  }

  public function delItemByIid(int $i_id)
  {
    return $this->where('i_id=' . $i_id)->relation("Example")->delete();
  }

  public function delItemByDid(int $d_id)
  {
    return $this->where('d_id=' . $d_id)->relation("Example")->delete();
  }

  public function delItemByUid(int $u_id)
  {
    return $this->where('u_id=' . $u_id)->relation("Example")->delete();
  }
  
}

 ?>